package com.xdtech.play.controller;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;

import com.xdtech.sys.aspect.SystemControllerLog;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.xdtech.play.service.PlayStakeService;
import com.xdtech.play.vo.PlayStakeItem;
import com.xdtech.web.controller.BaseController;
import com.xdtech.web.model.Pagination;
import com.xdtech.web.model.ResultMessage;

/**
 * 
 * @author max.zheng
 * @create 2016-05-08 23:48:33
 * @since 1.0
 * @see
 */
@Controller
@Scope("prototype")
public class PlayStakeController extends BaseController{
	private Log log = LogFactory.getLog(PlayStakeController.class);
	@Autowired
	private PlayStakeService playStakeService;
	@RequestMapping(value="/playStake.do",params = "playStake")
	public ModelAndView skipPlayStake() {
		return new ModelAndView("play/playStake/playStake_ftl");
	}
	
	@RequestMapping(value="/playStake.do",params="loadList")
	@ResponseBody
	public Map<String, Object> loadList(PlayStakeItem item,Pagination pg) {
		Map<String, Object> results =  playStakeService.loadPageDataByConditions(pg,item,"findPlayStakeByCondition");
		return results;
	}
	
	@RequestMapping(value="/playStake.do",params = "editPlayStake")
	@SystemControllerLog(description = "编辑")
	public ModelAndView editPlayStake(HttpServletRequest request,Long playStakeId) {
		if (playStakeId!=null) {
			request.setAttribute("playStakeItem", playStakeService.loadPlayStakeItem(playStakeId));
		}
		return new ModelAndView("play/playStake/editPlayStake_ftl");
	}
	
	@RequestMapping(value="/playStake.do",params = "savePlayStake")
	@ResponseBody
	@SystemControllerLog(description = "保存")
	public ResultMessage savePlayStake(PlayStakeItem item) {
		ResultMessage r = new ResultMessage();
		if (playStakeService.saveOrUpdatePlayStake(item)) {
			r.setSuccess(true);
		}else {
			r.setSuccess(false);
		}
		return r;
	}
	
	@RequestMapping(value="/playStake.do",params = "deletePlayStakeItems")
	@ResponseBody
	@SystemControllerLog(description = "删除")
	public ResultMessage deletePlayStakeItems(String ids) {
		ResultMessage r = new ResultMessage();
		if (StringUtils.isNotEmpty(ids)) {
			String[] tempIds = ids.split(",");
			List<Long> playStakeIds = new ArrayList<Long>();
			for (String id : tempIds) {
				playStakeIds.add(Long.valueOf(id));
			}
			playStakeService.deletePlayStakeInfo(playStakeIds);
			r.setSuccess(true);
		}else {
			r.setSuccess(false);
		}
		return r;
	}

}
